/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
/*
 * Created on 6 juil. 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package fr.jade.service.fm.repairScheduler;

import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.api.control.IllegalBindingException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;

import fr.jade.base.JadeBaseComponent;
import fr.jade.event.Event;
import fr.jade.event.EventHandler;
import fr.jade.util.JadeException;

/**
 * @author ssicard
 *
 */
public abstract class AbstractScheduler extends JadeBaseComponent implements EventHandler, BindingController  {
	
  protected static final String eventOutItfName = "event-out";
  protected EventHandler eventOut;
	
	public abstract void handleEvent(Event e) throws JadeException;
	
//	 BindingController
	public void bindFc(String itfName, Object itfValue) throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException {

		if (itfName.equals(eventOutItfName)) {
			eventOut = (EventHandler) itfValue;
		}else {
		  super.bindFc(itfName, itfValue);
		}

	}

	public String[] listFc() {
	  String[] listItf = new String[] { eventOutItfName };
		return super.concat(listItf, super.listFc());
	}

	public Object lookupFc(String itfName) throws NoSuchInterfaceException {
		if (itfName.equals(eventOutItfName)) {
			return eventOut;
		}
		return super.lookupFc(itfName);
	}

	public void unbindFc(String itfName) throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException {
		if (itfName.equals(eventOutItfName)) {
			eventOut = null;
		} else {
		  super.unbindFc(itfName);
		}
	}
}
